package com.smartcampus.demo.controller;


import com.smartcampus.demo.domain.Gas;
import com.smartcampus.demo.repository.GasDao;
import com.smartcampus.demo.service.GasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/gas")
public class GasController {

    @Autowired
    private GasService gasService;

    @GetMapping
    public List<Gas> getAllGas() {
        return gasService.getAllGas();
    }

    @GetMapping("/{id}")
    public Gas getGasDataById(@PathVariable Long id) {
        return gasService.getGasById(id);
    }

    // 获取最新的 n 个数据
    @GetMapping("/latest/{n}")
    public List<Gas> getLatestNGasData(@PathVariable int n) {
        return gasService.getLatestNGas(n);
    }
}
